import React, { useEffect } from 'react';
import { DocumentEditor } from '@onlyoffice/document-editor-react';

const onDocumentReady = (event) => {
    console.log("Document is loaded");
};

const onLoadComponentError = (errorCode, errorDescription) => {
    console.error("Error loading component:", errorCode, errorDescription);
};

const FilePreview = () => {
    useEffect(() => {
        console.log("FilePreview component mounted");
    }, []);

    return (
        <div style={{width:'100%',height:'100%'}}>
            <DocumentEditor
                style={{ width: '100%', height: '100%' }}
                id="docxEditor"
                // documentServerUrl="http://47.109.181.53:8005/"
                documentServerUrl="http://192.168.7.111:8001/"
                config={{
                    document: {
                        lang:'zh-CN',

                        url: "https://oss.generatech.cn/test/test1.docx"
                        // url: "http://192.168.0.42:9000/attachment/013bdb473737ae474d1fb2f4010f8abd"
                    },
                    editorConfig:{
                        user:{
                            name:'admin',
                            id:'admin'
                        },
                        mode: 'view', // 设置为 'view' 以禁用编辑
                        lang:'zh-CN',
                    },
                    // editorConfig: false, // 禁用编辑功能
                    documentType: "word",
                }}
                events_onDocumentReady={onDocumentReady}
                onLoadComponentError={onLoadComponentError}
            />
        </div>
    );
};

export default FilePreview;
